Okay.
So today we're going to have a look at one of our first services called Tween Service.
Now a tween service is just such a cool service and really like showing people this because it's really,
really cool basically.
Okay.
And it takes some of the stuff we've done previously in things like for loops and stuff and making it
a lot more advanced.
Okay, so first off, what actually is a service?
Well, everything we currently have in explorer, they're all services.
Some of them actually have service at the end of their name like um server script service or sound service
or text chat service.
So these are all default services that you can use in your game.
Some are more important than others okay.
Obviously workspace is a very key service.
Um, server script service can allow you to make run code on the server.
So they're all pretty, pretty cool and really pretty useful.
Okay.
Um, but there's a lot more services than these ones here.
Okay.
There are lots of other services that you can use to do all kinds of cool things.
Okay.
They're just not listed on here.
The reason why is, um, because there's like lots and lots like 50 plus, and there's just not enough
room for all of these on here.
And to have all those options for player to use at once, it's necessarily needed.
And these services aren't really, um, relating to objects, they're more relating to scripting.
So there's no point having them here if you're not going to do anything with them basically.
So there are almost lots of other options which are not listed on the explorer.
And one of those is called tween service.
So let's add a script, um, into this part over here and add in a script here.
Okay.
So we first need to kind of fetch tween service because tween service, the service wanting to use today
um, is not accessible already.
You can't start typing with functions and things like that because we haven't got it already.
It's kind of hidden away almost, for us to get it to use and to get it.
We basically say game and we use a function called Get Service like this here, which returns the service
we're wanting to fetch, and in here in speech marks, because these are class names and they're objects
almost.
We can fetch a service.
Now here a list of all the different services you can choose from.
And hopefully you can see now that there are so many that, um, having all of these open would just
be really, um, it would really lag out, you know, the game, it'd be the performance wouldn't be
great and it's just not needed.
Okay.
We're wanting to batch tween service here like that.
There.
Now what actually is tween service.
Well tween service allows you to create um smooth tweens.
Um, which can change the, the properties of an object between from one value to another.
A tween is like an animation.
So we're basically so you can basically smoothly transition the properties of an object from one to
another.
For example, I could smoothly move this part from here to here using a string without it looking all
bumpy and without doing it in jumps, saying we're going to do it by 0.1 each time.
If you zoom in close enough, it will all be bumpy.
Um, tween service doesn't do that.
So kind of like how um, some examples of for loops is by moving the part upwards by ten stars.
For example.
This is that button with a lot of other options.
And you'll find actually using tween service in your game can really give it more life.
And um, I think it's a very, very useful service to take your game from, you know, okay.
To really good just because of the extra life and the extra coolness it adds, basically.
Okay, um, right.
Enough of that.
We're going to use tween servers quite a lot.
So I'm going to make this, make this code here variable.
So local tween service.
Is equal to game, game service, train service.
You don't necessarily need to need to get train service unless you're going to use it.
So you don't need to make 20 variables.
Getting all the services you only need.
You only need to get them when you need them.
Okay.
Um, now train service, um, is very based on variables.
Okay.
Basically, because there's only one line that you need to write to in order to do train service, which
is basically tween service colon create, which is how you create a tween.
Okay, in order to do this, you need three things.
You need the instance.
So the object you're wanting to animate between info, which is basically some settings you can change,
and a property table which is a table of all the properties you're wanting to change.
Now we could all put it into here in one line, but it will be an extremely long line and be quite difficult
to read.
So I'm going to go through it by making some variables and then putting it into here later.
But just know that you can do it or do it in only a few lines instead.
So it'll be quite long and laid out.
But it's just a process of learning, and you won't necessarily have to do that if you're making it
in a game yourself.
Okay, so let's do it in order.
So the first thing we need to do is get the instance.
So get the object.
That's nice and easy.
Local parts.
Is it a script or parents like that far fetched apart?
Okay.
First one done.
Second one we had some extra information we wanted to add.
This is things like some some settings you can change of between.
So to do this let's create a variable.
Again these are all my variables.
So we're going to plug in to that function at the end.
So let's say local.
Okay, here's where it gets a bit a bit interesting because the usual the most obvious thing to call
it would be tween info, but that's taken.
So sometimes making this variable is a bit of a pain because think back right back to variables.
You can't name a variable, a keyword that's already taken.
So we can't call this tween info.
I'm going to call it, um.
Uh, what we call it.
Um.
Part tween info.
Okay, sometimes you have to make some weird weird named variables for this, unfortunately.
But yeah.
Okay.
Um, so this is equal to.
And for this we use tween info dot new.
And this basically stores some parameters that you can change.
Um.
Of the tween okay.
And there's lots of different ones here.
So I'm going to do is I'm going to lay this out in a nice way.
So I'm going to press enter.
Oh enter like this here I'm going to put each new parameter on its own line just so it's nice and laid
out for you.
But remember you don't necessarily have to do this.
It's just for layout purposes so you can learn a bit better.
Okay, so the first one is the time.
And this accepts as a number value.
So how long does the tween last.
I'm going to say a nice 10s like this here.
And remember each one needs a comma in it just after it.
Just like how you when you're using a vector three, you'd write a comma after each number.
You do the same here.
But because because I'm listing them in its own line, you might, you might, you might forget it basically.
Um, basically is the length length of tween.
Okay.
Next up is the easing style.
What's for easing style?
Um, this is the kind of style of the animation.
So there's a couple of different styles.
You can make a linear animation so it goes from one property to another in a linear kind of fashion.
So there's no speeding up, there's no slowing down.
There's none of that other stuff.
The other ones like elastic and bounce, which do all kind of cool effects.
Okay, I'm going to play around with a couple of these.
Um, but again, definitely something you want to play around with yourself.
Okay.
So to fetch this it's an enum value.
You can see we want to access here enum dot easing style.
So enum dot easing style dot.
And here are all the options here.
So linear here says moves at constant speed exponential which reduces speed reduces very quickly as
the tween approaches the target bounce which bounces back backwards multiple times after reaching the
target before eventually settling.
And lots of other ones here as well.
Okay, so some of these are a bit more mathsy than others, but um, definitely experiment of a couple
as they are honestly really cool.
Okay.
Um, I'm just going to go linear to start off with, but I will show you maybe 1 or 2 other options
later on.
Okay.
So this is the style of tween.
Okay.
The third one is the easing direction in easing direction.
And you've got three options for this.
You have in, out, in or out.
And this is basically where the easing style is applied.
So if you want the easing style to be applied in both directions, you want to pick in out.
If you only want it to be applied on the forward direction use in and reverse direction use out.
Put it to mention that before I explained it, but tweens can also be reversed so you can change the
property and then change it back to its existing value.
When you're changing it to the property, that's the in.
And when you're changing it, reverse the back to what it what it was before.
That's two out basically.
Okay.
Usually you'd use in out.
But again it depends on what you want pretty much.
Okay.
And so this is.
When?
The style is applied.
Okay.
Next one is the repeat count.
This is the amount of times that the tween repeats.
Now, this is quite funny, actually.
Um, when I first started learning tween service, I wanted to use this for an OBE.
Okay?
And I wanted this to repeat forever.
So I thought, okay, let's make this forever.
Let's say I want to repeat it for 999999999999999999 like that there okay.
So it's going to repeat forever.
Now sure.
That basically repeats forever.
But um with this, if you want it to repeat forever, you just need to write a number that's less than
zero.
So minus one for example, minus one would then mean it would repeat forever.
So instead of writing so many nines okay, you can or a massive, massive number, you can just write
minus one to make it repeat forever.
Okay.
Wish I knew that when I first started learning this.
Um, so this is the, um, number of times it repeats.
Okay.
And finally, we're not finally just yet.
There's one more after this reverses.
So basically once it's done the animation, so once it's converted it to the properties you want it
to change, is it going to convert back.
So can it occur in like a cycle where it continuously happens again and again.
You would write true or you write false okay I'm going to write true as I think the tweens look the
coolest when reverse is on.
But again it's up to up to you and what you usually want to have.
Reverse.
So this is um reverses and the last one is the delay time if you would want if a delay time.
This basically means when you play the tween it wakes up, waits a few seconds before it starts playing.
I'm going to set this to be zero.
I don't really use delay time that often, but it is there if you want to.
So this is the delay time.
Okay, so quite a few options there okay.
But it's just worth trying out really and experimenting with some of these options okay.
Um, a lot of stuff in this section.
There's lots of a lot more content to know.
So while I guess.
Yeah.
So while in the previous section, the stuff I was teaching you, all of the content is extremely important
and you will need to remember the majority of it.
In this case, it's all very important.
But if you don't remember tween service off by heart after this lesson, that is okay because you can
always refer back to this video if you are wanting to use tween service, eventually you will remember
it.
But I'll be completely honest with you, for some of these services that I'm using, I will have something
just to the side of me when I'm recording this, telling me how to do it because, um, let's face it,
um, a game pass game passes.
For example, if you want to make game passes, you would use a service for that in a game you'd probably
only want to make.
I only want to use it once to make some game passes.
It's not something you're going to be using again and again and again.
So it's quite difficult to remember it off by heart.
So as long as you get the general idea of some of these services, that's completely fine.
That's all I'm asking for.
Really.
You don't really need to remember these off by heart, okay.
But if you want, if you do remember off a heart.
Perfect.
But if you don't, it's okay.
Basically.
Okay.
Um, cool.
Let's move on.
Now to the third one we need to put in, which are the properties of tween.
These are the properties you're wanting to change.
Um, so yeah, the the properties are wanting to change basically not too much explanation.
They're needed.
I'm going to make a table for these called local tween properties.
Um tables.
Use these brackets.
Remember.
And inside here we're going to write in some properties you want to change.
Now the only rule with these is you can only change properties that are number based.
You can't use this for material or um, or I wouldn't say color, but you can um or name or anything
like that because they're not number based.
You can't smoothly transition them.
It can only be properties that you can smoothly transition.
Okay.
So I'm going to say size is equal to vector three dot new say 25 by 25 by 25.
This is an important point.
Um, why am I not saying part dot size like that there?
Well, basically because we're already going to give it, um, the instance we're doing this on, we
don't actually need to we don't actually need to reference it.
We just need to save a name of the property and then its value.
This is very interesting.
This is one of the only times that you will change a property without referencing it first.
Okay.
So much of it might take a bit of getting used to, but um, yeah, you don't need to write it basically.
And if you do write it, it will be classed as wrong.
It will throw an error.
So just be careful of that one okay.
After that we're going to write my second one which is going to be color.
So color is equal to color three.
Let's use dot for this time.
Let's pick a nice color.
Let's pick a red ready kind of orange color.
There we go.
Let's pick orange like that there okay.
And finally its changing position.
To equal Vector3 dot new.
Let's say zero 2020.
Okay.
So we've got our three sections here to add in.
We've got for instance the tween info and between properties.
Okay.
Now all we need to do is create the tween.
And to do that we're going to make a variable for this.
Like everything just so it's nice and laid out.
So our tween is equal to we're going to reference tween service and say tween service colon create.
That's the function that allows us to create our tween.
Here we put in our three bits.
So first one is the instance which is the part.
Second is the tween info which we have part tween info.
And the third is the property table which is tween properties there.
So you can put these in directly without making these variables.
But you can see how it just is laid out a bit nicer when you do do it this way.
So it's completely up to you when you code if you'd like to do it this way, but for explanations,
I'd recommend.
And when you first started learning this, I would probably recommend doing it like this.
It just makes it easier to learn.
Okay, then finally we write the one line of code which isn't a variable, which is tween colon.
Play like that there.
Okay.
And that's it.
So quite a quite a long bit of quite a long bit of code there.
But hopefully none of the code is too advanced.
Um, it's mostly just a lot of making variables and a lot of assigning things.
But um, yeah, some of these services, you do need to write a fair bit bit of code in order to do
it.
You'll probably be writing more code than you will have done in the previous section.
Um, but yeah, it's definitely worth it though, because it looks really cool when you try it out.
So let's go over to here and run the game and we're able to see what this looks like.
So there you go.
This is the result of it.
Now this is extremely cool and I really like tweens as be able to make something like this in a game
is so cool.
Okay, um, you can use tweens for guys as well.
It's a very common use of them.
If you want guys to kind of slide in from the left of your screen, absolutely.
Do it that way.
If you want parts to become larger and smaller like this, absolutely do it that way as well.
Ah, obby we made previously, we could have used tween service in order to move the parts instead of
using a repeat loop and two for loops.
So because if we go into it like this here, it's completely smooth.
There's no kind of jump to anything.
It's completely smooth how it's moving.
So looks really nice and I think it's really cool.
Okay.
I absolutely love doing service.
I think it's really amazing.
Um, I do just want to show you, before we finish the lesson off so many different styles of tween
that you can choose from.
So we've got linear here.
Let's try exponential and see what that one looks like.
Exponential will look something like this here.
So it starts off slow and very quickly jumps into place like that there.
Okay.
Um, you could also try, um, bounce.
Which look something like this here.
So it kind of bounces up and down.
You can just see how these are so cool.
I really like them.
Um, but yeah.
One more want to show you, which is, um, elastic.
Let me try that one out.
It moves back a bit.
And then just like that, they're turned green for a minute.
I think it's because it goes over and then back a bit.
Um, but yeah.
So hopefully you enjoyed looking at some of these.
Okay.
Um, definitely practice this.
Okay.
As it's quite a lot of code here.
But as long as you remember the general format of this.
So first the instance, then the information, then the properties, then you create it and play it.
That's all you need really need to know.
And make sure you reference the tween service before you start anything else out.
Okay.
So V service is a really cool.
And I think tween service is more of a visual service.
So you really get to see some of your options playing out.
But it is really cool.
I really like it.
Okay.
Hope you like it too.
Okay, so have a play around with that and join me in the next lesson.
We're going to have a look at another service called User Input Service, which is also really cool.
Okay, so join me then.